package com.stlm2.controller;

import com.stlm2.dems.entity.User;
import com.stlm2.dems.service.GoodsCategoryService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

/**
 * Created by apple on 2017/10/18.
 */
@Controller
@RequestMapping("/goodsCategoryC")
public class GoodsCategoryController {
    @Resource
    private GoodsCategoryService goodsCategoryService;


    /**
     * 分类查询
     * ffl
     * 2017-10-16 10:48:45
     * @param token
     * @param level
     * @param name
     * @param parentCategoryId
     * @param isValid
     * @param categoryType 分类类型  1普通分类 2特殊分类
     * @param pageNu 第几页
     * @return
     */
    @ResponseBody
    @RequestMapping(value="/search.json",produces="application/json;charset=UTF-8")
    public String searchCategory(String token , String level ,String name , String parentCategoryId,String isValid,String categoryType,String pageNu) {
        return goodsCategoryService.searchCategory(token, level, name, parentCategoryId, isValid, categoryType, pageNu);
    }

    /**
     * 添加 商品分类
     * ffl
     * 2017-10-13 14:52:58
     * @param token
     * @param name 分类名称
     * @param summary 分类简介
     * @param level  分类等级
     * @param imgUrl logo图片路径
     * @param parentCategoryId 父分类id
     * @param sort  优先级
     * @param categoryType 分类 类型  1普通分类 2热门品牌
     * @return
     */
    @ResponseBody
    @RequestMapping(value="/toAdd.json",produces="application/json;charset=UTF-8")
    public String AddCategory(String token,String name, String summary, String level,String imgUrl,String  parentCategoryId, String sort,String categoryType,String linkUrl) {
        return goodsCategoryService.AddCategory(token, name, summary, level, imgUrl, parentCategoryId, sort, categoryType, linkUrl);
    }
    /**
     * 编辑商品分类
     * ffl
     * 2017-10-13 17:36:15
     * @param token
     * @param categoryId 商品分类id
     * @param name 名称
     * @param summary 简介
     * @param imgUrl logo图片路径
     * @param sort 优先级
     * @param categoryType 分类类型  1普通分类 2特殊分类
     * @param isValid  是否有效  1有效  0无效
     * @return
     */
    @ResponseBody
    @RequestMapping(value="/edit.json",produces="application/json;charset=UTF-8")
    public  String editCategory(String token,String  categoryId, String name, String summary, String imgUrl, String sort,String categoryType,String isValid,String linkUrl) {
        return goodsCategoryService.editCategory(token, categoryId, name, summary, imgUrl, sort, categoryType, isValid,linkUrl);
    }


    /**
     * 获取一级分类
     * ffl
     * 2017-10-18 09:44:34
     * @return
     */
    @ResponseBody
    @RequestMapping(value="/firstLevel.json",produces="application/json;charset=UTF-8")
    public  String getFirstLevel(){
        return goodsCategoryService.getFirstLevelCategory();
    }
    /**
     * 根据一级分类获取二级分类
     * ffl
     * 2017-10-17 14:57:03
     * @return
     */
    @ResponseBody
    @RequestMapping(value="/secondLevel.json",produces="application/json;charset=UTF-8")
    public String getByFirstLevelCategory(String parentCategoryId){
        return goodsCategoryService.getByFirstLevelCategory(parentCategoryId);
    }


    /**
     * 根据id获取分类 详情
     * ffl
     * 2017-10-18 10:10:02
     * @param token
     * @param id
     * @return
     */
    @ResponseBody
    @RequestMapping(value="/getById.json",produces="application/json;charset=UTF-8")
    public String getByIdForDetail(String token ,String id){
        return goodsCategoryService.getByIdForDetail(token, id);
    }


    @RequestMapping(value="/list",produces="application/json;charset=UTF-8")
    public ModelAndView list(ModelAndView modelAndView){
        modelAndView.setViewName("/goodsCategory/list");
        return modelAndView;
    }

    @RequestMapping(value="/add",produces="application/json;charset=UTF-8")
    public ModelAndView add(ModelAndView modelAndView){
        modelAndView.setViewName("/goodsCategory/add");
        return modelAndView;
    }

    @RequestMapping(value="/detail",produces="application/json;charset=UTF-8")
    public ModelAndView edit(ModelAndView modelAndView){
        modelAndView.setViewName("/goodsCategory/detail");
        return modelAndView;
    }


}
